/**
 * 根级别的 mutation
 */
import storage from '@/storage'

/**
 * 更新loading，主要用于非组件内
 * @param state
 * @param status
 * @constructor
 */
export const UPDATE_LOADING = (state, status) => {
  state.loadingCount += (status ? 1 : state.loadingCount > 0 ? -1 : 0)
}
/**
 * 页面切换动画的滑动方向
 * @param state
 * @param direction
 * @constructor
 */
export const UPDATE_DIRECTION = (state, direction) => {
  state.direction = direction
}

/**
 * 更新auth_token
 * @param state
 * @param payload
 * @constructor
 */
export const UPDATE_AUTH_TOKEN = (state, payload) => {
  storage.set('AUTH_TOKEN', payload, { 'expireDays': 7 })
  state.authToken = payload
}

/**
 * 清除auth_token
 * @param state
 * @constructor
 */
export const REMOVE_AUTH_TOKEN = (state) => {
  storage.remove('AUTH_TOKEN')
  state.authToken = ''
}
